package com.kelaite.procurement.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Logger;

/**
 * 
 * @author Allen
 * 
 */
public class ValidationUtil {

	private static final Logger logger = (Logger) LoggerFactory
			.getLogger(ValidationUtil.class);

	public static boolean isMobileNumber(String mobiles) {
		Pattern p = Pattern
				.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		logger.debug("mobile number validation result: " + m.matches());
		return m.matches();
	}

	/**
	 * 验证输入的邮箱格式是否符合
	 * 
	 * @param email
	 * @return 是否合法
	 */
	public static boolean isEmailValid(String email) {
		String EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
        Boolean result = email.matches(EMAIL_REGEX);
		logger.debug("email validation result: " + result);
		return result;
	}

}